<?php

namespace app\controller;

use app\BaseController;
use app\constants\HttpStatus;
use app\constants\ServiceStatus;
use app\model\AdminUserModel;
use app\traits\ControllerTrait;
use think\facade\Db;
use think\facade\App;

/**
 * Class AdminUser
 * @package app\controller\admin
 */
class AdminUser extends ControllerTrait
{
    public function index()
    {
        //
    }

    /**
     * 登录校验
     */
    public function login()
    {
        $param = $this->request->param();
        $rule = [
            "account|用户名" => "require",
            "password|密码" => "require"
        ];
        $this->validate($param, $rule);

        $user=app('adminUserModel')->where(
            [
            'account' => $param['account'],
            'password' => $param['password'],
            'status' => 1,
         ] )->find();

        if (!empty($user)) {
            $data = array(
                'msg' => '登录校验成功',
                'token' => app("jwt")->signToken($user["id"])
            );
            $this->success($data);
        } else {
            $data = array(
                'msg' => '登陆失败,账号或密码错误',
            );
            $this->success( $data);
        }
    }

    /**
     * 登录用户信息
     */
    public function userInfo(){
//        halt($this->uid);
        $user = app("adminUserModel")
            ->field(["id","avatar","account","mark","phone"])
            ->find($this->uid);

        $data = array(
            'msg' => '登录用户基本信息',
            'userInfo' => $user
        );
        $this->success($data);
    }

}
